package org.zb.shiro.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zb.shiro.dao.UserMapper;
import org.zb.shiro.model.User;

import com.github.pagehelper.PageHelper;

@Service
public class UserService {

	@Autowired
	private UserMapper userMapper;
	
	public List<User> searchAll(Map<String, Object> user) {
		PageHelper.startPage(1, 10);
		return userMapper.searchAll(user);
	}
	
    public User findById(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }
    
    public User findByUsername(String username) {
    	return userMapper.selectByUsername(username);
    }
    
    public int saveUser(User user){
    	return userMapper.insert(user);
    }
    
    public int updateUser(User user) {
    	return userMapper.updateByPrimaryKeySelective(user);
    }
    
    public int patchDeleteByIds(Long[] ids){
    	return userMapper.patchDeleteByIds(ids);
    }
    
    public int deleteUser(User user) {
    	return userMapper.deleteByPrimaryKey(user.getId());
    }
}
